home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / fdate42a.zip / FDATE.DOC < prev    next >
Text File  |  1992-01-06  |  40KB  |  985 lines

  1. FDATE      Version 4.2a                          Jan 03, 1992
  2. ===================================================================
  3. FDATE: a utility for date manipulation in batch files.
  4. ===================================================================
  5. Stephen Ferg             5113 N. 8th Road, Arlington, VA 22205-1201
  6. Voice (703) 525-2241     CompuServe 73377,1157
  7.  
  8. =======================================================================
  9. Format:
  10. FDATE /Ffunc /Adate /Bdate /Iformat /Oformat /Nnum /Ddayofweek /Pstring
  11. =======================================================================
  12.  
  13.  
  14. FDATE PARAMETERS
  15. ================
  16.  
  17. The parameters that are required depend on the function requested.
  18. Parameters that are specified, but not needed, are ignored.
  19. Executing FDATE without any parameters displays a brief help screen.
  20.  
  21. Parameters can be in any order and upper or lower case.
  22.      Note that although format specifications are not case sensitive,
  23.      they ARE "text sensitive".  If any characters are missing,
  24.      added, or mistyped, the format specification will be rejected.
  25.      (A common mistake is to enter "/format" instead of "/Fformat".
  26.       This mistake can be avoided by using the /Ff function alias.)
  27.  
  28.  /F  requests a particular FDATE function
  29.      If this parameter is not specified, or is specified incorrectly,
  30.      FDATE displays a help screen.  If you unexpectedly get the help
  31.      screen displayed, you probably have omitted the /F parameter.
  32.  
  33.  /N  number of days (always a number)
  34.  /A  date A         (for math functions, a number)
  35.  /B  date B         (for math functions, a number)
  36.  
  37.  /I  specifies format of input date(s)
  38.  /O  specifies format of output date
  39.  
  40.  /L  specifies language of output.   If omitted, English is assumed.
  41.      /Leng  English-language output  [the default]
  42.      /Lfr   French-language output
  43.  
  44.  /P  specifies a prefix string for the output
  45.      This optional parameter may always be specified or omitted.
  46.      Prefix string must be enclosed in single or double quotes
  47.      EXAMPLE:  FDATE /Fformat /Atoday /O"mn zd, ccyy" /P"Today is "
  48.  
  49.      Note that multiple spaces will be removed from a /P paramaeter
  50.      string, so formatting of /P strings cannot be controlled using
  51.      spaces.  To format strings, use periods or ASCII 255 (hex'ff')
  52.      as filler.
  53.  
  54. ERROR HANDLING
  55. ==============
  56.  
  57.    If FDATE detects an error:
  58.  
  59.      (1) it will return an errorlevel of 1 (rather than 0), and
  60.      (2) its output will be 3 lines:
  61.        * the word ERROR
  62.        * a DOS batch-file ECHO statement that displays an error message
  63.        * a DOS batch-file PAUSE statement
  64.  
  65.    If Fdate output is displayed directly, or redirected to NUL:
  66.    you can detect an error by testing the errorlevel for a value of 1.
  67.  
  68.    If Fdate output is piped to an environment manipulation utility such
  69.    as STRINGS or GET, the environment variable will be set to ERROR.
  70.    Errorlevel will be set by STRINGS/GET, and will probably be 0.
  71.    In such a case, the only way to detect an error is to test the
  72.    environment variable for the value ERROR.
  73.  
  74.    If FDATE output is redirected to a batch file, which is then
  75.    CALLed to set an environment variable, the batch file will:
  76.      * set the environment variable to ERROR,
  77.      * ECHO the error message, and
  78.      * pause.
  79.    You can detect an error by testing errorlevel for the value 1
  80.    either before or after you CALL the batch file.
  81.    You can detect an error by testing the environment variable for the
  82.    value ERROR, AFTER you have CALLed the batch file.
  83.  
  84. ----------------------------------------------------------------------
  85.  
  86.  EXAMPLE:
  87.    rem use FDATE to check validity of year in parm %1
  88.    Fdate /Ff /Imm-dd-ccyy /ATT-TT-%1 /Occyy /P"Received year parm: "
  89.    if errorlevel 1 echo Year parm [%1] is not valid.
  90.    if errorlevel 1 goto endit
  91.  
  92.  EXAMPLE:
  93.    rem use FDATE to verify %1, and GET to put it into %year%
  94.    Fdate /Ff /Imm-dd-ccyy /ATT-TT-%1 /Occyy | GET ZE /V%year% >nul
  95.    if (%year%)==(ERROR) echo Year parm [%1] is not valid.
  96.    if (%year%)==(ERROR) goto endit
  97.  
  98.  EXAMPLE:
  99.    rem use FDATE to verify %1, call a batch file to put it into %year%
  100.    Fdate /Ff /Imm-dd-ccyy /ATT-TT-%1 /Occyy /P"@set year=">junktemp.bat
  101.    call junktemp.bat
  102.    del  junktemp.bat
  103.    if errorlevel 1 echo Year parm [%1] is not valid.
  104.    if errorlevel 1 goto endit
  105.  
  106. SYMBOL CONVENTIONS
  107. ==================
  108.  
  109. The following symbols are used in specifying date formats:
  110.  
  111. SYMBOL  EXAMPLE   MEANING
  112. ------  -------   -------------------------------------
  113. cc        19      century
  114. yy        85      year
  115. mm        02      month
  116. zm         2      month without leading zero
  117. dd        09      day
  118. zd         9      day   without leading zero
  119. mn       January  month name
  120. mn3      Jan      month name, first 3 characters only
  121. dow      Tuesday  day of week
  122. dow3     Tue      day of week, first 3 characters only
  123. dow#      3       day of week as a number (Sunday=1, Monday = 2, etc.)
  124. today             is a "pseudodate" representing the current date
  125. t                 is an alias for the "today" pseudodate
  126. hh:mm    09:05    hours and minutes
  127. ss        09      seconds
  128.  
  129.  
  130.  
  131. PSEUDODATES
  132. ===========
  133.  
  134. t (or today)
  135.           can be used with either /A or /B, e.g. /Atoday or /At.
  136.  
  137. EXAMPLE
  138.           rem Get the date that is 90 days from today
  139.           FDATE /Fadd /N90 /Atoday /Omm-dd-ccyy
  140.           FDATE /Fadd /N90 /At     /Omm-dd-ccyy
  141.  
  142.           rem determine if this year is a leapyear
  143.           FDATE /Ff /At /OLY
  144.  
  145. tt        when used in place of a 2-digit DD string, will cause
  146.           Fdate to use today's day-of-the-month.
  147.           Example:    FDATE /Ff /Imm-dd-ccyy /A01-tt-1992 /Od1
  148.  
  149. tt        when used in place of a 2-digit MM string, will cause
  150.           Fdate to use today's month.
  151.           Example:    FDATE /Ff /Imm-dd-ccyy /Att-01-1992 /Od1
  152.  
  153. tt        when used in place of a 2-digit YY string, will cause
  154.           Fdate to use today's year (CCYY).
  155.           Example:    FDATE /Ff /Imm-dd-yy /A01-01-tt /Od1
  156.  
  157.           Note that TT can NOT be used for only the YY part of a CCYY
  158.           input year.  The following, for example, is NOT valid:
  159.           Example:    FDATE /Ff /Imm-dd-ccyy /A01-01-19tt /Od1
  160.  
  161. tttt      when used in place of a 4-digit CCYY string, will cause
  162.           Fdate to use today's year (CCYY).
  163.           Example:    FDATE /Ff /Imm-dd-ccyy /A01-01-tttt /Od1
  164.  
  165.  
  166. EXAMPLES:
  167.  
  168. Show the first Monday in the second quarter of this year
  169. FDATE /Fw /Iccyymmdd /Atttt0301 /D2 /N1 /Od1 /P"First Monday in QTR#2: "
  170.  
  171. Show the last Friday on/before the 15th of this month.
  172. FDATE /Fw /Iccyymmdd /Atttttt15 /D6 /N-1 /Od1 /P"Friday before the 15th: "
  173.  
  174.  
  175. INPUT FORMATS
  176. =============
  177.  
  178. FORMAT      EXAMPLES      DISCUSSION
  179. ------      ---------     -----------------------------
  180. ccyymmdd    19922002
  181.  
  182. mm-dd-ccyy  02-20-1992    In an input format specification, the dash
  183.             02/20/1992    symbols represent ANY non-numeric symbol.
  184.              2/20/1992    Leading zeros need not be present.
  185.  
  186. mm-dd-yy    02-20-92      In this input format,
  187.             02/20/92      cc=19 is assumed if YY is greater than 20
  188.             02/20/92      otherwise, cc=20 is assumed
  189.  
  190.  
  191. NOTE
  192. If ALL input dates are specified using the "today" pseudodate, (i.e.
  193. /At, /Bt) then it is not necessary to supply an input format using /I.
  194.  
  195.  
  196.  
  197.  
  198. OUTPUT FORMATS
  199. ==============
  200.  
  201. FORMAT        EXAMPLES      DISCUSSION
  202. ------        ---------     -----------------------------
  203. ccyy          1992
  204. ccyymm        199202        useful for triggering monthly processing
  205. ccyymmdd      19920220      useful for putting current date in filename
  206.   yymmdd        920220      useful for putting current date in filename
  207.     mmdd          0220
  208. dd-mn3-yy     02-Feb-92     CompuServe-style date
  209.  
  210. In the following formats, months precede days (American style)
  211. ------------------------------------------------------------------
  212. mm/dd/ccyy    02/20/1992
  213. mm-dd-ccyy    02-20-1992
  214. zm/zd/ccyy     2/20/1992    no leading zeros in day or month
  215. zm-zd-ccyy     2-20-1992    no leading zeros in day or month
  216. mm/dd/yy      02/20/92
  217. mm-dd-yy      02-20-92
  218. zm/zd/yy       2/20/92      no leading zeros in day or month
  219. zm-zd-yy       2-20-92      no leading zeros in day or month
  220.  
  221. In the following formats, days precede months  (European style)
  222. ------------------------------------------------------------------
  223. dd/mm/ccyy    02/20/1992
  224. dd-mm-ccyy    02-20-1992
  225. zd/zm/ccyy     2/20/1992    no leading zeros in day or month
  226. zd-zm-ccyy     2-20-1992    no leading zeros in day or month
  227. dd/mm/yy      02/20/92
  228. dd-mm-yy      02-20-92
  229. zd/zm/yy       2/20/92      no leading zeros in day or month
  230. zd-zm-yy       2-20-92      no leading zeros in day or month
  231.  
  232. ------------------------------------------------------------------
  233.  
  234. Day-of-the-week output formats
  235. ------------------------------------------------------------------
  236.  
  237. dow#           5            Sunday=1, Monday=2 .... Saturday=7.
  238.  
  239. dow            Thursday     name of day of week
  240.                Jeudi        if /Lfr specified
  241.  
  242. dow3           Thu          first 3 characters of name of day of week
  243.                Jeu          if /Lfr specified
  244.  
  245. ------------------------------------------------------------------
  246.  
  247.  
  248. LY              0           1 if year is a leapyear, otherwise 0.
  249.                                ------------------------------------
  250.                                365 + this number gives total
  251.                                      number of days in the year.
  252.                                 28 + this number gives total
  253.                                      number of days in February.
  254.                                ------------------------------------
  255.  
  256. d1           Saturday, February 5, 1992
  257.              le Samedi 5 Fevrier 1992      [/Lfr specified]
  258.  
  259. t1            9:05 pm
  260.  
  261. HH:MM        09:05   ("Military time") (9:05 am)
  262.              21:05                     (9:05 pm)
  263.  
  264. HH:MM:SS     21:05:30
  265.  
  266. full          9:05 pm on Saturday, February 5, 1992
  267.               9:05 pm le Samedi 5 Fevrier 1992      [/Lfr specified]
  268. -----------------------------------------------------------------------
  269. NOTE that the following formats contain embedded spaces.  Consequently
  270. they must be enclosed in double quotes. EXAMPLE: /O"mn zd, ccyy".
  271. -----------------------------------------------------------------------
  272. "zd mn ccyy"      5 February 1992
  273. "zd mn, ccyy"     5 February, 1992
  274. "mn3 dd ccyy"     Feb 05 1992
  275. "mn3 dd, ccyy"    Feb 05, 1992
  276. "mn zd, ccyy"     February 5, 1992
  277.  
  278.  
  279.  
  280. "JULIAN" OUTPUT FORMATS
  281. =======================
  282.  
  283. FORMAT        EXAMPLES      DISCUSSION
  284. ------        ---------     -----------------------------
  285.  
  286. julian            311       BUSINESS "Julian date" expressed as number
  287.                             of days since January 1 of the same year.
  288.  
  289. day#           727198       TRUE "Julian date" expressed as number
  290.                             of days since January 1, 0001.
  291.  
  292. minute#         33088       "Julian minutes": time expressed as number
  293.                             of minutes  since midnight, January 1, 1990.
  294.  
  295. second#        633088       "Julian seconds": time expressed as number
  296.                             of seconds  since midnight, January 1, 1990.
  297.  
  298. ----------------------------------------------------------------------
  299.    Running FDATE with /O parameter for a "Julian time" produces a
  300.    number based on the current time of day and the date in the /A parm.
  301.  
  302.    If, on January 10, 1992 at 2 pm, you run FDATE this way:
  303.        FDATE /Ff /Atoday /Ominute#
  304.    it will produce the Julian minute for January 10, 1992 at 2 pm.
  305.  
  306.    If, on January 10, 1992 at 2 pm, you run FDATE this way:
  307.        FDATE /Ff /A01-15-1992 /Imm-dd-ccyy  /Ominute#
  308.    it will produce the Julian minute for January 15, 1992 at 2 pm.
  309. ----------------------------------------------------------------------
  310.  
  311. DATE FUNCTIONS
  312. ==============
  313.  
  314. FUNCTION  FDATE /Ffunc /Adate /Iformat /Oformat
  315. --------  -------------------------------------------
  316. format    this is a synonym for function "f"
  317.  
  318. f         returns /Adate in format specified by /Oformat
  319.           Since /Aformat and /Oformat can be different, the FORMAT
  320.           function is used to change a date from one format to another.
  321.           Because of the wide variety of output formats, the FORMAT
  322.           function can also be used to determine the day of week of the
  323.           date, whether the date is in a normal or leap year, etc.
  324.  
  325. EXAMPLES
  326.           FDATE /Ff /A19920101 /Iccyymmdd /O"mn zd, ccyy"
  327.           FDATE /Ff       /Atoday         /Od1
  328.           FDATE /Fformat  /Atoday         /Od1
  329.  
  330.  
  331.  
  332. FUNCTION  FDATE /Ffunc /Nnumdays /Adate /Iformat /Oformat
  333. --------  -------------------------------------------
  334. add       Adds      /Ndays to   /Adate, produces date in /Oformat format
  335. sub       Subtracts /Ndays from /Adate, produces date in /Oformat format
  336.  
  337. EXAMPLES
  338.           FDATE /Fadd /N90 /A01-01-1992 /Imm-dd-ccyy /Od1
  339.           FDATE /Fsub /N90 /A01-01-1992 /Imm-dd-ccyy /Od1
  340.           FDATE /Fadd /N90 /Atoday                   /Od1
  341.  
  342.  
  343.  
  344. FUNCTION  FDATE /Ffunc /Adate /Bdate /Iformat
  345. --------  -------------------------------------------
  346. comp      compares the dates specified on the /A and /B parms.
  347.           returns         when
  348.             LT            /A  is less than    (earlier than) /B
  349.             EQ            /A  is equal to     (same as)      /B
  350.             GT            /A  is greater than (later than)   /B
  351.  
  352. dif       Returns number of days between /Adate and /Bdate
  353.           Order of the two dates is not significant.
  354.           Note that for DIF, both dates must be in the SAME
  355.           format, the input format specified in /Iformat.
  356.           If the two dates are not in the same format, reformat one
  357.           of the dates using the /Ff function and
  358.           a utility like STRINGS or GET.
  359.  
  360. EXAMPLES
  361.           FDATE /Fdif /A01-01-1992 /B11-11-1992  /Imm-dd-ccyy
  362.           FDATE /Fdif /A11-11-1992 /B01-01-1992  /Imm-dd-ccyy
  363.           FDATE /Fdif /Atoday      /B01-01-1992  /Imm-dd-ccyy
  364.  
  365.  
  366. FUNCTION  FDATE /Ffunc /Adate /Iformat /Oformat /Ddow#  /Ndow-count
  367. --------  -------------------------------------------
  368. w         W (weekday) function.
  369.           This function accepts a date specification in parm /A and
  370.           returns the date of the /Nth /Day-of-the-week
  371.           before or after /Adate.  For example:
  372.  
  373.           If    /A specifies November 14, 1992
  374.                 /D specifies the number for Thursday (i.e., 5)
  375.                 /N specifies a week count of 3
  376.           then /Fw returns the date of the third Thursday after
  377.           November 14, 1992. (See full example, below)
  378.  
  379.           Note that /N may be negative.  If, in the above example, /N
  380.           is specified as -3, then Fdate returns the date of the third
  381.           Thursday BEFORE November 14, 1992.
  382.  
  383.           If the date specified on the /A parms falls on the same day
  384.           of the week as was specified on the /D parm, then that will
  385.           be considered to be the first date meeting that day-of-week
  386.           criterion.  That is, If November 14, 1992 fell on a
  387.           Thursday, and if /N was 1 or -1, then the output date would
  388.           be the same as the input date, i.e.  November 14, 1992.
  389.  
  390.           The acceptable values for /N (number of weeks) is in
  391.           the range of 99..-99.  A value of zero (i.e. /N0) is invalid.
  392.  
  393. EXAMPLES
  394.      find date of Thanksgiving (4th Thursday in November) in 1992
  395.          FDATE /Fw /A11-01-1992 /Imm-dd-ccyy /D5 /N4 /Od1
  396.      returns: Thursday November 26, 1992
  397.  
  398.      find the beginning of the work-week (Monday, 2nd day of week)
  399.      AFTER Thanksgiving, 1992
  400.          FDATE /Fw /A11-26-1992 /Imm-dd-ccyy /D2 /N1 /Od1
  401.  
  402.      find the beginning of the work-week (Monday, 2nd day of week)
  403.      BEFORE Thanksgiving, 1992
  404.          FDATE /Fw /A11-26-1992 /Imm-dd-ccyy /D2 /N-1 /Od1
  405.  
  406.  
  407. MATH FUNCTIONS
  408. ==============
  409.  
  410. FUNCTION  FDATE /Ffunc /Anum  /Bnum
  411. --------  -------------------------------------------
  412.  
  413. #add      returns the sum of the integers specified
  414.           on the /A and /B parms.  Can be used to calculate the
  415.           "Julian" minute(second, date) in the future from a given
  416.           "Julian" minute(second, date).
  417.  
  418. #sub      (not supported)
  419.           no numeric subtraction operation (as such) is supported.
  420.           Often, you will find that #dif will do what you want.
  421.           #dif is the same as subtraction in which the smaller
  422.           number is subtracted from the larger number; it will never
  423.           return a negative number.  If you really MUST have
  424.           subtraction, which might return a negative result, you can
  425.           add two numbers, one of which is a negative number.
  426.           For example, to subtract 3 from 2:
  427.               FDATE /F#add /A2 /B-3          [ returns: -1 ]
  428.  
  429. #dif      returns the difference between the integers specified
  430.           on the /A and /B parms.  Can be used to calculate the
  431.           number of minutes(seconds, days) between two
  432.           "Julian"  minutes(seconds, dates).
  433.  
  434. #comp     compares the integers specified on the /A and /B parms.
  435.           returns         when
  436.             LT            /A  is less    than /B
  437.             EQ            /A  is equal   to   /B
  438.             GT            /A  is greater than /B
  439.  
  440.  
  441. PUTTING FDATE OUTPUT INTO AN ENVIRONMENT VARIABLE
  442. =================================================
  443.  
  444. FDATE's output is written to standard output, that is, it is displayed
  445. on the screen.  Output can be redirected to a file, or it can piped to
  446. a utility (such as STRINGS or GET) that will put it into an
  447. environment variable.
  448.  
  449. Manipulating the environment is an incredibly tricky business.  There
  450. are questions of the local versus master environment, the version of
  451. DOS you are running, and the environment under which you are running
  452. (DOS, Windows, Carousel).  In order to keep FDATE focussed on
  453. date-related issues, I have not attempted to make it put its output
  454. directly into an environment variable.
  455.  
  456. One way to put FDATE's output into an environment variable is to use
  457. the /P (prefix string) feature to create a DOS "SET" statement,
  458. redirect the output to a batch file, and CALL the batch file.
  459. Since CALL first appeared in DOS 3.3, you will need DOS 3.3 or
  460. greater to use this technique.
  461.  
  462.   FDATE /Ff /Atoday /O"mn zd, ccyy" /P"@SET FDATE=" >JUNKTEMP.BAT
  463.   call JUNKTEMP.BAT
  464.   del  JUNKTEMP.BAT
  465.  
  466. There are also shareware and public domain utilities that are written
  467. specifically to manipulate environment variables, and do that job very
  468. well.  FDATE's output can be put into an environment variable by piping
  469. it to one of these utilities.  When piping FDATE output to a utility,
  470. you can prevent the output from being ECHOed to the screen by
  471. redirecting the output to NUL.
  472.  
  473.    EXAMPLE: use STRINGS to put date into DATE1 environment variable
  474.    FDATE /Ff /At /Od1 | STRINGS date1= ASK >NUL
  475.  
  476.    -----------------------------------------------------------------
  477.    I recommend Bob Stephan's GET and PC Magazine's STRINGS.
  478.    As of December 30, 1991, the current version of GET is GET25.ZIP.
  479.    On CompuServe, use IBMFF to look for GET*.ZIP in CIS:IBMSYS
  480.    GET is also available from the Public Software Library in Houston.
  481.    On CompuServe, look for STRING.ZIP in Utilities Lib of ZNT:UTILFORUM
  482.    -----------------------------------------------------------------
  483.  
  484. =======================================================================
  485. EXAMPLE #1
  486. Redirect FDATE output to a file, or to a callable batch file,
  487. or pipe it to STRINGS or GET to store it in an environment variable
  488. =======================================================================
  489. rem display Fdate output on screen
  490. FDATE /Ff /At /Od1 /P"Today is "
  491.  
  492. rem Redirect FDATE output to a file
  493. FDATE /Ff /At /Od1 /P"Today is " >FDATE.OUT
  494.  
  495. rem Redirect FDATE output to a callable batch file
  496. FDATE /Ff /Atoday /O"mn zd, ccyy" /P"@SET DATE1=" >JUNKTEMP.BAT
  497. call JUNKTEMP.BAT
  498. del  JUNKTEMP.BAT
  499.  
  500. rem Pipe FDATE output to STRINGS to store it in DATE1 environment var
  501. FDATE /Ff /Atoday /O"mn zd, ccyy" |STRINGS date1= ASK >NUL
  502.  
  503. rem Pipe FDATE output to GET to store it in DATE1 environment var
  504. FDATE /Ff /Atoday /O"mn zd, ccyy" |GET ZE /Vdate1 >NUL
  505.  
  506.  
  507.  
  508. =======================================================================
  509. EXAMPLE #2
  510. Find the difference (in days) between two dates in different formats
  511. Use GET to put FDATE output into environment variables.
  512. =======================================================================
  513. set date1=05-10-1992
  514.  
  515. rem reformat date literal into same format as date1
  516. FDATE /Ff /Imm-dd-yy   /A05-08-92 /Omm-dd-ccyy | GET ZE /Vdate2>NUL
  517.  
  518. rem get difference between date1 and date2
  519. FDATE /Fdif /Imm-dd-ccyy /A%date1%  /B%date2%| GET ZE /vdiff>NUL
  520.  
  521. echo The difference is %diff% days.
  522.  
  523.  
  524.  
  525.  
  526. =======================================================================
  527. EXAMPLE #3
  528. Schedule a program to run at a specified time in the future.  Note that
  529. this involves a lot of disk activity because DOS re-reads the batch
  530. file from disk every time it does a GOTO LOOPTOP.  If you do this, it
  531. is a good idea to run the batch file from a RAM DISK.
  532. =======================================================================
  533. REM GET CURRENT JULIAN MINUTE AND PUT IN ENVIRONMENT VARIABLE RUNTIME
  534. FDATE /Ff /At /Ominute#  |STRINGS RunTime= ASK >NUL
  535.  
  536. REM ADD 120 MINUTES (2 HOURS) TO ENVIRONMENT VARIABLE RUNTIME
  537. FDATE /F#add /A%RunTime% /B120 |STRINGS RunTime= ASK >NUL
  538.  
  539. REM LOOP UNTIL NOWTIME HAS REACHED RUNTIME
  540. :LoopTop
  541.   FDATE /Ff /At  /Ominute#   |STRINGS NowTime=  ASK >NUL
  542.   FDATE /F#comp  /A%NowTime% /B%RunTime% |STRINGS TimeComp= ASK >NUL
  543.   if (%TimeComp%)==(LT) goto loopTOP
  544. :LoopEnd
  545.  
  546. echo STARTING EXECUTION OF APPLICATION: [program name]
  547.  
  548.  
  549.  
  550. =======================================================================
  551. EXAMPLE #4
  552. Rename file BACKUP.LOG to a name that contains today's date
  553. =======================================================================
  554. FDATE /Ff /Atoday /Oyymmdd /P"@SET DATE1=" >JUNKTEMP.BAT
  555. call JUNKTEMP.BAT
  556. del  JUNKTEMP.BAT
  557. ren  BACKUP.LOG  BK%DATE1%.LOG
  558. SET  DATE1=
  559.  
  560.  
  561.  
  562. =======================================================================
  563. EXAMPLE #4b
  564. Use FDATE to rename a log file to a name that will be unique within a
  565. minute time-frame.  This is a way to keep an historical record of a
  566. series of log files.  Since the file will retain its original date/time
  567. stamp, you will still be able easily to tell when it was created.
  568. In this example, we use GET to put the FDATE output into
  569. environment variable TEMPVAR.
  570. =======================================================================
  571. FDATE /FF /At /Ominute# | GET ZE /Vtempvar >nul
  572. REN online.log %tempvar%.log
  573. SET tempvar=
  574.  
  575.  
  576.  
  577. =======================================================================
  578. EXAMPLE #5
  579. Find the calendar date corresponding to Julian date 1992:200
  580. by adding 200 to the last day of the previous year.
  581. =======================================================================
  582. FDATE /Fadd /A12-31-1991 /Imm-dd-ccyy /N200 /Od1
  583.  
  584.  
  585.  
  586. =======================================================================
  587. EXAMPLE #6
  588. Check to see if parameter %1 is a valid year (CCYY)
  589. =======================================================================
  590. @echo off
  591. rem determine if value sent in through parameter %1 is a valid year
  592. Fdate /Ff /Imm-dd-ccyy /A01-01-%1 /Od1 >nul
  593. if errorlevel 1 echo Parm 1 was not a valid year: %1
  594. if errorlevel 1 goto endit
  595.  
  596. echo PUT YOUR BATCH PROCESSING HERE, USING YEAR VALUE OF: %1
  597.  
  598. :endit
  599.  
  600.  
  601.  
  602. =======================================================================
  603. EXAMPLE #7
  604. Find the 4th Thursday in November (Thanksgiving)
  605. =======================================================================
  606. Fdate /Fw /D5 /N4 /A11-01-%year% /Imm-dd-ccyy /Od1 /P"Thanksgiving: "
  607.  
  608.  
  609.  
  610. =======================================================================
  611. EXAMPLE #8
  612. Show the number of the anniversary for some special event.
  613. =======================================================================
  614. SEE HOLIDAYS.BAT
  615.  
  616.  
  617. =======================================================================
  618. EXAMPLE #9
  619. Run a program once a day, when you boot for the first time that day.
  620. =======================================================================
  621. @echo off
  622. cls
  623.  
  624. REM -------------------------------------------------------------------
  625. REM Run daily processing once a day.  Put this code in AUTOEXEC.BAT.
  626. REM This batch file requires DOS 3.3+, since it uses CALL.
  627. REM -------------------------------------------------------------------
  628. if not exist LastRun.BAT goto RunNow
  629. REM LastRun.Bat will set env var LASTRUN to date AUTOEXEC was last run.
  630. call LastRun.BAT
  631.  
  632. REM Compare today's date to date in LASTRUN
  633. Fdate /Fcomp /Imm-dd-ccyy /At /B%LastRun% /P"@set COMP=">junktemp.BAT
  634. call junktemp.BAT
  635. del  junktemp.BAT
  636.  
  637. IF (%COMP%)==(EQ) goto NoRun
  638. REM if user reset system clock, today's date may be less than LASTRUN
  639. IF (%COMP%)==(LT) goto NoRun
  640.  
  641. rem Daily processing hasn't been run today. Run it.
  642.  
  643. echo RUNNING ONCE A DAY PROCESSING: Job 1
  644. echo RUNNING ONCE A DAY PROCESSING: Job 2
  645. echo RUNNING ONCE A DAY PROCESSING: ............. etc.
  646.  
  647. rem ------------------------------------------------------------------
  648. rem Save today's date in a new version of LastRun.BAT
  649. rem Note that this will be executed only if daily processing runs to
  650. rem completion without hanging the machine or aborting the batch file.
  651. rem ------------------------------------------------------------------
  652. Fdate /Ff /Omm-dd-ccyy /At /P"@set LastRun=">LastRun.BAT
  653.  
  654. :NoRun
  655. set LastRun=
  656. set COMP=
  657.  
  658. FDATE'S ALGORITHMS
  659. ==================
  660.  
  661.  
  662. FDATE IS DESIGNED FOR BUSINESS, NOT HISTORICAL, APPLICATIONS
  663. ============================================================
  664. FDATE is intended for business applications, not historical ones.
  665. As far as FDATE is concerned, the calendar has followed the same
  666. pattern, unchanged, since January 1, 0001.
  667.     -------------------------------------------------------------------
  668.     FDATE does not take into account historical changes in the calendar
  669.     such as the glitch in English dates that occurred when Britain
  670.     moved from the Julian to Gregorian calendar in the 18th century,
  671.     or Russia made the same move in the early 20th century.
  672.     -------------------------------------------------------------------
  673.  
  674.  
  675. FDATE'S BASE DATE
  676. =================
  677.   Internally, date manipulations are based on translating a calendar
  678.   date into an "absolute" or "TRUE Julian" date:  a date expressed
  679.   as the number of days from some day in the distant past.
  680.   FDATE's base date is January 1, 0001 (i.e. day 1 of month 1 of year 1)
  681.   FDATE's absolute date for January 1, 0001 is      1.
  682.   FDATE's absolute date for January 1, 1992 is 727198.
  683.  
  684.  
  685. FDATE'S LEAP YEAR ALGORITHM
  686. ===========================
  687.     Every year evenly divisible by 4 IS a leap year
  688.       EXCEPT THAT
  689.         Every year evenly divisible by 100 IS NOT a leap year
  690.           EXCEPT THAT
  691.             Every year evenly divisible by 400 IS a leap year
  692.     .
  693.     Using this algorithm
  694.          1983  is not a leap year
  695.          1984  is     a leap year
  696.          1900  is not a leap year
  697.          2000  is     a leap year
  698.  
  699.     See "A Machine Algorithm for Processing Calendar Dates", by
  700.          Henry F. Fliegel (Georgetown University Observatory) and
  701.          Thomas C. Van Flandern (U.S. Naval Observatory)
  702.          COMMUNICATIONS OF THE ACM, Volume 11, Number 10, October 1968
  703.  
  704. There is supposedly a new adjustment to the leapyear algorithm,
  705. which specifies the additional exception:
  706.  
  707.               EXCEPT THAT
  708.                 Every year evenly divisible by 4000 IS a leap year
  709.  
  710. See "Bit By Bit" column, COMPUTER LANGUAGE, November 1989, p. 148.
  711. This adjustment is not part of FDATE's leapyear algorithm.
  712. Unless your application is working with dates 2,000 years in the
  713. future, the lack of this exception will be irrelevant for you.
  714.  
  715. TIC.BAT
  716. =======
  717.  
  718. TIC.BAT is a sample application that uses FDATE to create a "tickler
  719. file" batch file.  The default name for the file is C:\TICKLER.BAT.
  720.  
  721. In order to use TIC on a regular basis, you should:
  722.  
  723.    * If you wish, use your favorite text editor to modify TIC.BAT
  724.      so it sets TicBAT to a different file name for the tickler
  725.      batch file.  Note that you need to specify the full filename,
  726.      including path and extension.
  727.  
  728.    * Put TIC.BAT in a directory that is in your PATH.
  729.  
  730.    * add the following lines to your AUTOEXEC.BAT file:
  731.          CLS
  732.          call TIC today
  733.          pause
  734.      This will cause the tickler batch file to be run when you
  735.      boot your computer, showing you the day's appointments.
  736.  
  737. To add a new "tickle", invoke TIC.  The first parm must be the date
  738. of the desired tickle, in the format mm/dd/yy.  (You may use the
  739. pseudodate TT for the current month or year, if you wish.)
  740.  
  741. The date parameter must be followed by 1 - 18 words of description.
  742. NOTE: DOS batch files strip commas out of their input parameters, so
  743. any commas in your description will be lost.
  744.  
  745.   EXAMPLE:  tic 5/5/92 Cinco de Mayo party w/ Susan: El Charro @ 6pm
  746.   EXAMPLE:  tic 5/5/tt Cinco de Mayo party w/ Susan: El Charro @ 6pm
  747.  
  748. Running TIC without any parms, will cause it to display a HELP screen.
  749.   EXAMPLE:  tic
  750.  
  751. You can check your tickler file appointments for a particular day
  752. at any time by invoking TIC with only a date parm, or with only
  753. the pseudodate T or TODAY as a parm.
  754.  
  755.   EXAMPLE: tic t         displays appointments for today
  756.   EXAMPLE: tic today     displays appointments for today
  757.   EXAMPLE: tic 5/5/92    displays appointments for May 5, 1992
  758.   EXAMPLE: tic 5/5/tt    displays appointments for May 5 of this year
  759.   EXAMPLE: tic tt/5/tt   displays appointments for the 5th of this month
  760.  
  761. If the tickler batch file does not exist, nothing will be displayed.
  762.  
  763. After a while the tickler batch file will become very long, filled with
  764. "dead tickles".  You can edit it with a text editor to remove the dead
  765. tickles, or simply delete it and let TIC create a new one the next time
  766. you use TIC to add a tickle.
  767.  
  768.  
  769. USE AND DISTRIBUTION OF FDATE
  770. =============================
  771.  
  772. FDATE is freeware.  Although the author retains the copyright, FDATE
  773. can be copied, used, and distributed freely as long as both FDATE.EXE
  774. and its associated doc files (FDATE.DOC, FDATEX.BAT, HOLIDAYS.BAT)
  775. are not altered and are distributed together.
  776.  
  777. FDATE can be included in shareware packages as long as both FDATE and
  778. its doc files are included in the shareware package.
  779.  
  780. If you have received FDATE as part of some larger shareware package,
  781. please be aware that you may freely use, copy, and distribute FDATE
  782. without paying a fee for, or registering, the package.
  783.  
  784. The author explicitly disavows any claim whatsoever about the
  785. functionality of the software, and disclaims liability for anything and
  786. everything bad that might happen in connection with, before, during, or
  787. after using it.  I have tried to make FDATE work right, but everybody
  788. makes mistakes, so you use FDATE at your own risk.
  789.  
  790. I don't know if people will find FDATE useful, and I'd like to find
  791. out.  If you find FDATE useful and use it on a regular basis, I'd
  792. appreciate it if you would drop me a short note via US mail or
  793. CompuServe, telling me about how you are using FDATE.
  794.  
  795. If you need other input/output formats, or if you need a different
  796. leapyear algorithm, please contact the author.
  797.  
  798.  
  799.  
  800. UPDATES AND CURRENT VERSION OF FDATE
  801. ====================================
  802.  
  803. You will always be able to find the most recent version of FDATE on
  804. CompuServe.  The filename will be FDATE.ZIP, and it will be available in
  805. one of the libraries in the CIS:IBMSYS forum and one of the libraries in
  806. the ZNT:UTILFORUM forum.  You can find it by using cross-library
  807. searching, looking for the filename FDATE.ZIP or the keyword FDATE.
  808.  
  809. Feel free to post copies of FDATE.ZIP on any BBS that you wish, but
  810. please do not upload it to any CompuServe library.  As long as I am the
  811. only one putting copies of FDATE onto CompuServe, we can keep confusion
  812. over versions to a minimum.
  813.  
  814.  
  815. FDATE REVISION HISTORY
  816. ======================
  817.  
  818. Letters appended to version numbers indicate modifications to
  819. the doc files, without any modification to the FDATE.EXE software.
  820. Asterisks (*) indicate most important changes in the new version.
  821.  
  822. 1.1   Oct 01, 1991
  823.       First version of FDATE
  824.  
  825. 1.2   Oct 15, 1991
  826.       Replaced shareware date routines with Ferg routines
  827.       NOTE THAT THERE IS NOT MUCH ERROR-CHECKING IN THIS VERSION.
  828.  
  829. 1.2d  Oct 16, 1991
  830.       Minor changes to show redirection and piping of FDATE output
  831.       Revised discussion of how FDATE may be distributed.
  832.       Added note on business-related, non-historical purpose of FDATE
  833.       Added note on 4000-year leap-year exception
  834.  
  835. 1.2e  Oct 17, 1991
  836.       Added note on why FDATE doesn't directly set an Env variable
  837.  
  838. 2.0a  Nov 05, 1991
  839.       Modified Help display to show parameters and their meanings
  840.       Added output format YYMMDD
  841.       Added output format minute# and second#
  842.       Added function #dif
  843.       Added test of GET and STRINGS      to FDATEX.BAT
  844.       Added test of minute# and second#  to FDATEX.BAT
  845.  
  846. 2.1a  Nov 06, 1991
  847.       Added /P parameter and modified documentation accordingly
  848.       Added JULDATE output format
  849.       Minor changes and reformatting to documenation
  850.  
  851. 2.2a  Nov 08, 1991
  852.       Added example showing how to put current date in a filename
  853.       Added MMDD output formats
  854.  
  855. 2.3a  Nov 09, 1991
  856.       Added /L (language parameter) to allow French-language output
  857.       Added the following output formats
  858.          full
  859.          "mn3 zd, ccyy"
  860.          "zd mn, ccyy"
  861.          "zd mn ccyy"
  862.          European-style date formats
  863.                in which day occurs before month (e.g. dd/mm/ccyy)
  864.  
  865. 2.4a  Nov 10, 1991
  866.       Fixed display of time in /Ofull so that a minutes value of
  867.             less than 10 would display with a leading zero:
  868.             e.g. "10:08 am" instead of "10:8 am".
  869.  
  870. 2.5a  Nov 13, 1991
  871.       Added output format CCYYMM
  872.  
  873. 2.6a  Nov 25, 1991
  874.       Added function "F" (/Ff) as an synonym for /Fformat
  875.       Split FDATEX.BAT off from FDATE.DOC into its own file
  876.  
  877. 2.6b  Dec 02, 1991
  878.       Modified this doc file to reflect new /Ff feature
  879.  
  880. 2.7a  Dec 07, 1991
  881.       Added CompuServe-style output format: dd-mn3-yy.
  882.                                    Example: 07-Dec-91
  883.  
  884. 2.8a  Dec 08, 1991
  885.       Added output format d1.    Example:  Saturday December 7, 1991
  886.       Added output format t1.    Example:  9:05 am
  887.       Added "t" alias for "today" pseudodate.
  888.  
  889.       Corrected FDATE "help" display which had incorrectly shown
  890.          dd-mn3-yy as an input (rather than an output) format.
  891.       Modified documentation and FDATEX.BAT to reflect software changes.
  892.       Extensively re-wrote and re-arranged FDATEX.BAT to make it
  893.          more user-friendly.
  894.       In documentation:
  895.          corrected the formats for European dates, which had incorrectly
  896.          been shown as having the same format as American dates.
  897.  
  898. 2.8b  Dec 09, 1991
  899.       In documentation:
  900.          Added example showing how to use fdate to create a
  901.          time-stamped filename.
  902.  
  903. 2.9a  Dec 26, 1991
  904.       Added STRINGS and GET info to HELP screen.
  905.       In documentation:
  906.          Added example: how to find calendar date of Julian date
  907.  
  908. 3.0a  Dec 27, 1991
  909. *     =============== MAJOR BUG FIX ==============================
  910. *     Fixed bug in TRUEDATE date arithmetic routine that caused
  911. *     incorrect dates to be returned for the last 2 or 3 days of
  912. *     some months.
  913. *     ============================================================
  914.       Added output formats ccyy, hh:mm, and hh:mm:ss.
  915.       Replaced output format JULDATE with JULIAN
  916.              JULDATE retained for compatibility, but not documented.
  917.       Modified this doc file and FDATEX.BAT accordingly.
  918.  
  919. 3.1a  Dec 28, 1991
  920.       Fixed bug: error messages were ignoring the /P parm
  921.       added HOLIDAYS.BAT to distribution package
  922.       Replaced output format LEAPYR with LY
  923.              LEAPYR retained for compatibility, but not documented.
  924.       Added new feature: when an error is detected:
  925.              output string is "ERROR", and
  926.              errorlevel is set to 1.
  927.       Changed assumed century on input formats that require only YY.
  928.              Now, if year is LT/EQ 20, a century of 20 is assumed.
  929.              FDATE will now be able to function nicely until year 2020.
  930.       Modified this doc file and FDATEX.BAT accordingly.
  931.  
  932. 3.2a  Dec 29, 1991
  933.       Added COMP (date compare) function
  934.       Added RUN-ONCE-A-DAY example, which uses new COMP function
  935.       Added error-trapping for dates before year 1 and after year 9999.
  936.       Fixed minor error in HELP screen (dif does NOT require /O).
  937.       Modified this doc file and FDATEX.BAT accordingly.
  938.  
  939. 3.2b  Dec 30, 1991
  940.       Fixed two bugs in this doc file. (Thanks to Luther Schliesser
  941.          for the bug report.)   My phone number was wrong, and the
  942.          values returned by the leapyear function (0,1) were reversed.
  943.       Fixed my phone number in the HELP screen.
  944.       Minor changes in the examples in this DOC file.
  945.  
  946. 3.2c  Dec 31, 1991
  947.       Fixed bug in HOLIDAYS.BAT that showed New Year's Eve when
  948.             it should have showed New Year's Day.
  949.             (Thanks to Luther Schliesser for ANOTHER bug report.)
  950.       Modified HOLIDAYS.BAT to show Easter-related holidays 1992-2000
  951.       Modified HOLIDAYS.BAT to give an example of calculating
  952.           anniversaries for a user-specified "special date" (SD)
  953.  
  954. 4.1a  Jan 03, 1992
  955. *     Added ability to accept TT, TT, and TTTT
  956.             as pseudodates for current MM, DD, and CCYY.
  957. *     Added function: W  (i.e. /Fw)
  958.       Modified this doc file, FDATEX.BAT, and HOLIDAYS.BAT accordingly.
  959.  
  960.       Modified HOLIDAYS.BAT to use new /Fw to show Thanksgiving.
  961.       Added Luther Schliesser's anniversary code to HOLIDAYS.BAT
  962.       Added note on elimination of multiple spaces from /P strings.
  963.       Added note showing how to use #add and negative number to do
  964.             true subtraction.
  965.       Added note: UPDATES AND CURRENT VERSION OF FDATE
  966.  
  967. 4.2a  Jan 04, 1992
  968.       In FDATE.EXE:
  969.       Minor change to improve readability of an error message
  970.  
  971.       In FDATE.DOC:
  972. *     expanded discussion of how to check for errors using FDATE
  973.       added documentation for TIC.BAT
  974.  
  975.       In HOLIDAYS.BAT:
  976.       added Easter days for 1991 and 2001, Epiphany, Pentecost, etc.
  977.       fixed bug in algorithm for Ash Wednesday (thanks to L. Schliesser)
  978.       changed "Memorial Day"            , May 30
  979.            to "Memorial Day (observed)" , the last Monday in May
  980.       inspired by L.S.'s tickler for Sharon's birthday, added "tickler"
  981.            for 500th anniversary of Columbus' discovery of America
  982.  
  983.       Added TIC.BAT to FDATE distribution ZIP file
  984.       Started practice of highlighting important changes with "*"
  985.